home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / popup-menu-cdef ƒ / main.c next >
Encoding:
C/C++ Source or Header  |  1990-04-15  |  2.4 KB  |  103 lines  |  [TEXT/KAHL]

  1.  
  2. /*
  3.  * main.c for CDEF shell
  4.  *
  5.  * Copyright © 1990 Michael S. Engber. All rights reserved
  6.  */
  7.  
  8. /*
  9.  * Thanks to:
  10.  * Steve Hawley
  11.  *    Whose CDEF button source I used as an example. His source was
  12.  *    squirreled away in my archives & I can't recall how I got it.
  13.  *  Off the INTERNET I'm sure.
  14.  * Jean deCombret
  15.  *    Whose Jan '89 MacTutor article explained the "clean way"  to 
  16.  *    install a procedure as a fake CDEF.
  17.  */
  18.  
  19. #include "pup.h"
  20.  
  21. #define    WINDOW_ID    100
  22. #define JMP_INST 0x4EF9
  23.  
  24. typedef struct{
  25.     short    jmpInst;
  26.     ProcPtr    addrCDEF;
  27. }fakeCDEF,*fakeCDEF_p,**fakeCDEF_h;
  28.  
  29. static fakeCDEF_h installCDEF(int idCDEF){
  30.     fakeCDEF_h fakeH = (fakeCDEF_h)Get1Resource('CDEF',idCDEF);
  31.     (*fakeH)->jmpInst    = JMP_INST;
  32.     (*fakeH)->addrCDEF    = (ProcPtr)&mainCDEF;
  33.     return fakeH;
  34. }
  35.  
  36. main ()
  37. {
  38.     fakeCDEF_h fakeH;
  39.     
  40.     Rect r = {20, 30, 40, 260};
  41.     
  42.     ControlHandle    fontPup;
  43.     ControlHandle    resMenuPup;
  44.     
  45.     WindowPtr        mainWindow;
  46.     
  47.     InitGraf(&thePort);
  48.     InitFonts();
  49.     InitWindows();
  50.     InitMenus();
  51.     TEInit();
  52.     InitDialogs(0L);
  53.  
  54.     FlushEvents(everyEvent,0);
  55.     InitCursor();
  56.     
  57.     mainWindow = GetNewWindow(WINDOW_ID,0L,(WindowPtr)(-1L));
  58.     SetPort(mainWindow);
  59.     
  60.     fakeH = installCDEF(PUP_ID);
  61.  
  62.     fontPup = NewControl(
  63.                     mainWindow,        /* window to contain the pup */
  64.                     &r,                /* contrlRect */
  65.                     "\pfont pup:",    /* contrlTitle - used as pop-up title */
  66.                     true,            /* make it visible */
  67.                     1,                /* cntrlValue - selected item */
  68.                     0,                /* cntrlMin - make up a menu id */
  69.                     120,            /* cntrlMax - width of pop-up title box */
  70.                     16 * PUP_ID,    /* control definition ID */
  71.                     'FONT'            /* refCon - add fonts items */
  72.                 );
  73.     
  74.     OffsetRect(&r,0,25);
  75.     
  76.     resMenuPup = NewControl(
  77.                     mainWindow,        /* window to contain the pup */
  78.                     &r,                /* contrlRect */
  79.                     "\p",            /* contrlTitle - menu title is used */
  80.                     true,            /* make it visible */
  81.                     3,                /* cntrlValue - selected item */
  82.                     100,            /* cntrlMin - use menu with rsrc id 100 */
  83.                     120,            /* cntrlMax - width of pop-up title box */
  84.                     16 * PUP_ID,    /* control definition ID */
  85.                     0L                /* refCon - don't add any rsrc items */
  86.                 );
  87.  
  88.  
  89.     while(1) {
  90.         EventRecord        curEvent;
  91.         ControlHandle    curControl;
  92.  
  93.         if(GetNextEvent(everyEvent, &curEvent)){
  94.             if(curEvent.what == keyDown) ExitToShell();
  95.             if(curEvent.what == mouseDown){
  96.                 GlobalToLocal(&curEvent.where);
  97.                 if(FindControl(curEvent.where, mainWindow, &curControl))
  98.                     TrackControl(curControl, curEvent.where, 0L);        
  99.             }
  100.         }
  101.     }
  102. }
  103.